Tester - Unit Testing for Php
Unit testing library.
UNDER DEVELOPMENT: v0.3 is pretty functional, but this v1.0 is under development and not ready to use.
This README shall serve as the initial planning document for v1.0. Once v1.0 is ready, TODOs and DONEs should all be removed
Documentation
TODO (delete TODOs and TODO Notes) In the Documentation list below, a TODO without (parenthetical notes) means "THERE IS DOCUMENTATION TO WRITE". A TODO (with parenthetical notes) will specify otherwise, like 'TODO(contains todos)' if the referenced documentation file has its own TODOs to finish. Note that DONE
s will be added where appropriate, and then should be removed when all TODOs are completed.
- TODO (contains todos) Getting Started (below)
- TODO (link to issue template) @link(ReportBug, Report Bugs) or @link(RequestFeature, Request Features)
- Installation
- TODO(install via tag 1.x.x instead of v1.0.x-dev) Composer: @template(php/composer_install_inline)
- Globally: TODO(Add
phptest-global
bin script)-
mkdir ~/apps; cd ~/apps; git clone @template(git/CloneUrl) phptest; cd phptest; composer install;
- Add
alias phptest=~/apps/phptest/bin/phptest-global
to your~/.bashrc
file or~/.bash_profile
- Execute
phptest
instead ofvendor/bin/phptest
. (Automatically calls your git project's vendor/bin/phptest if it exists)
-
- Usage
- TODO(write docs, refactor/improve assertions) @link(Assertions) - Available assertions; add new assertions
- TODO(write docs, convert traits to helper objects) @link(Helpers) - databasing, sending http requests, and other utilites
- TODO(write docs, contains TODOs) @link(Configure) - If defaults are not sufficient
- TODO(May need more docs. May desire scrawl template for generation) @link(CLI) - (or use
vendor/bin/phptest help
) - TODO @link(WebRequests, Test Web Requests) to localhost, live test servers, or on production.
- TODO (write docs instead of just linking into code) @link(Example) - This library's tests
- TODO @link(CICD) - Automatically run tests when pushing to git or receiving pull requests
- Alternatives
- @link(phpunit) - Industry standard, popular, robust, feature rich, learning curve, class-oriented
- TODO(link to issue template?) @link(SuggestAlternative, Suggest Alternatives) or suggest changes to descriptions of existing alternatives
- Development
- TODO(contains todos) @link(Development)
- DONE @link(ChangeLog)
- DONE @link(License, MIT License)
Getting Started
Use defaults, or @link(Configure) as needed.
Follow steps below, or @link(Example, see an example).
Create a test
- TODO
vendor/bin/phptest create-test
- Follow the prompts, which will create a new test file
- Setup your test in the
testMain()
method (or create new testWhatever() methods)
A test is a single method within a class implementing the (TODO: Create interface) Tlf\Tester interface, prefixed with test
. Alternatively, use (TODO: add add_test()
method) $tester->add_test($callable)
in your (TODO: define scope & make variables available to bootstrap file) test/bootstrap.php
file.
For a test to pass, all assertions in the test must pass. If any assertions fail, or if there are no assertions, then the test fails.
Use $this->disable()
to disable the current test, so it doesn't count toward your pass/fail.
Tips
- TODO(fix access level on many tester methods, or refactor some out) Most accessible methods on
$this
are assertions. - TODO
$this
has multiple helper objects as properties. Trydb
,server
,exceptions
, andutility
Run your tests
-
vendor/bin/phptest
: Run all tests -
vendor/bin/phptest -test TestName
: Run tests with the given TestName (Supports multiple -test flags) -
vendor/bin/phptest -class ClassBaseName
: Run all tests for a class. (Supports multiple -class flags) -
vendor/bin/phptest help
: Help Menu
Screenshots & Examples
Also see the @link(CLI, CLI documentation).
CLI Help Menu
... include image here ...
Test Results
... test results ...
Example Test class
@file(test/input/Runner/run/Test.php)